package com.maxuxu.scihome.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.maxuxu.scihome.mapper.EmpMapper;
import com.maxuxu.scihome.pojo.Employee;
import com.maxuxu.scihome.pojo.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: EmployeeService
 * @author: Maxuxu
 * @date: 2022/7/5 15:11
 * @description: 服务类
 */
@Service
public class EmployeeService {
    @Autowired
    Employee employee;
    @Autowired
    Pages pages;
    @Autowired
    EmpMapper empMapper;

    public String insertEmployee(Employee employee){
        empMapper.insert(employee);
        return "插入成功";
    }
    public Pages selectPage(long current, long size){
        Page<Employee> Page =  empMapper.selectPage(new Page<>(current, size), null);
        List<Employee> records = Page.getRecords();
        long total = Page.getTotal();
        long pages = Page.getPages();
        long current1 = Page.getCurrent();
        long size1 = Page.getSize();
        this.pages.setPages(pages);
        this.pages.setCurrent(current1);
        this.pages.setSize(size1);
        this.pages.setTotal(total);
        this.pages.setRecords(records);
        return this.pages;
    }


    public Employee selectByAny(Employee Employee){
        QueryWrapper<Employee> wrapper = new QueryWrapper<>();
        wrapper.eq("name", Employee.getName());
        Employee Employee1 =  empMapper.selectOne(wrapper);
        return Employee1;
    }

    public void deletEmployee(List<Integer> list){
        empMapper.deleteBatchIds(list);
    }

    public void updateEmployee(String oldname,Employee Employee){
        UpdateWrapper<Employee> wrapper = new UpdateWrapper<>();
        wrapper.eq("name", oldname);
        empMapper.update(Employee, wrapper);

    }


}
